package cn.com.fone.modules.admin.common.service.impl;

import cn.com.fone.modules.admin.common.config.JedisClusterClient;
import cn.com.fone.modules.admin.common.domain.CacheQueryEntiry;
import cn.com.fone.modules.admin.common.service.QueryCacheService;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 查询redis集群缓存工具
 */
@Service
public class QueryCacheServiceImpl implements QueryCacheService {

    @Autowired
    private JedisClusterClient jedisClusterClient;

    public List<CacheQueryEntiry> queryCaches(String prefix) {
        // 根据前缀获取所有节点上的相关key
        prefix = "SMP*";
        List<String> list = jedisClusterClient.keys(prefix);
        List<CacheQueryEntiry> respList = Lists.newArrayList();
        list.forEach(v -> {
            CacheQueryEntiry cqEntity = new CacheQueryEntiry();
            cqEntity.setKey(v);
            respList.add(cqEntity);
        });
        return respList;
    }
}
